﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="details.aspx.cs" Inherits="DeansWsccProject.details" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript"><!--
function showHide(elementid){
    if (document.getElementById(elementid).style.display == 'none') {
        document.getElementById(elementid).style.display = '';
    }
    else {
        document.getElementById(elementid).style.display = 'none';
    }
}
//-->
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:GridView ID="eBookDetailsGridView" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <%# getEBookDownloadLink(Convert.ToString(Eval("eBookDownloadUrl")), "<img class='eBookImage' src='/" + Eval("eBookImage") + "' alt='" + Eval("eBookTitle") + " image not available' />", "<img class='eBookImage' src='/" + Eval("eBookImage") + "' alt='" + Eval("eBookTitle") + " image not available' />") %>
                    <br />
                    <span class="eBookDownloadLink"><%# getEBookDownloadLink(Convert.ToString(Eval("eBookDownloadUrl")), "Download Now!", "Register to Download") %></span>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-VerticalAlign="Top">
                <ItemTemplate>
                    <span style="text-decoration:underline; font-weight:bold;"><%# getEBookDownloadLink(Convert.ToString(Eval("eBookDownloadUrl")), Convert.ToString(Eval("eBookTitle")), Convert.ToString(Eval("eBookTitle"))) %></span>
                    <br />
                    <%# DeansWsccProject.App_Code.functions.getRating(Convert.ToString(Eval("eBookRating"))) %>
                    
                    <!-- Show no. reviews link only if eBook has been rated at least once -->
                    <span id="noReviewsLink" runat='server' Visible='<%# Convert.ToString(Eval("eBookRating")) != "" %>'>
                        <a href='/details.aspx?ID=<%# Eval("ID") %>#recent-reviews'>(<%# DeansWsccProject.App_Code.functions.getNoReviews(Convert.ToString(Eval("ID"))) %>Reviews)</a>
                    </span>
                    <br />
                    <br />
                    <b>Authored by</b>
                    <br />
                    <asp:Repeater ID="authorsRepeater" runat="server" DataSourceID="authorsSqlDataSource">
                        <ItemTemplate>
                            <a href='/profile.aspx?profileUserName=<%# DataBinder.Eval(Container.DataItem, "profileUserName") %>'><%# DataBinder.Eval(Container.DataItem, "FirstName") %> <%# DataBinder.Eval(Container.DataItem, "LastName") %></a>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                    <br />
                    <b>Released: </b><%# Convert.ToString(Eval("eBookReleaseDate")).Remove(10, 9) %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-VerticalAlign="Top">
                <ItemTemplate>
                    <b>Description</b>
                    <br />
                    <%# Eval("eBookDescription") %>
                    <br />
                    <br />
                    <b>Tags</b>
                    <br />
                    <asp:Repeater ID="tagsRepeater" runat="server" DataSourceID="tagsSqlDataSource">
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem, "tag") %>, 
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="authorsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DeansWsccProjectConnectionString %>" ProviderName="<%$ ConnectionStrings:DeansWsccProjectConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT [FirstName], [LastName], [profileUserName] FROM [eBookAuthorView] WHERE ([ID] = ?) ORDER BY [LastName], [FirstName]">
        <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="tagsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DeansWsccProjectConnectionString %>" ProviderName="<%$ ConnectionStrings:DeansWsccProjectConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT [tag] FROM [eBookTagView] WHERE ([ID] = ?) ORDER BY [tag]">
        <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <a href="javascript:showHide('write-review');"><h2>Click here to write a review of this eBook</h2></a>
    <div id='write-review' style="display:none;">
        <asp:PlaceHolder ID="phTbReviewerEmail" runat="server">
            Email: <asp:TextBox ID="tbReviewerEmail" runat="server" TextMode="Email"></asp:TextBox>
            <br />
        </asp:PlaceHolder>
    
        <ajaxToolkit:RoundedCornersExtender ID="phTbReviewerEmail_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="phTbReviewerEmail">
        </ajaxToolkit:RoundedCornersExtender>
    
        Title: <asp:TextBox ID="tbReviewTitle" runat="server"></asp:TextBox>
        <ajaxToolkit:RoundedCornersExtender ID="tbReviewTitle_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="tbReviewTitle">
        </ajaxToolkit:RoundedCornersExtender>
        <br />
        Review:<br />
        <asp:TextBox ID="tbReview" runat="server" Height="108px" TextMode="MultiLine" Width="301px"></asp:TextBox>
        <ajaxToolkit:RoundedCornersExtender ID="tbReview_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="tbReview">
        </ajaxToolkit:RoundedCornersExtender>
        <br />
        Rating: <ajaxToolkit:Rating ID="ajtkReviewRating" runat="server" MaxRating="10" CurrentRating="5" EmptyStarCssClass="emptyRatingStar" FilledStarCssClass="filledRatingStar" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"></ajaxToolkit:Rating>
        <br />
        Enter new tags separated by comma: <asp:TextBox ID="tbNewEBookTags" runat="server"></asp:TextBox>
        <ajaxToolkit:RoundedCornersExtender ID="tbNewEBookTags_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="tbNewEBookTags">
        </ajaxToolkit:RoundedCornersExtender>
        <br />
        <asp:CheckBoxList ID="cblEBookTags" runat="server" DataTextField="tag" DataValueField="ID" RepeatDirection="Horizontal"></asp:CheckBoxList>
        <ajaxToolkit:RoundedCornersExtender ID="cblEBookTags_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="cblEBookTags">
        </ajaxToolkit:RoundedCornersExtender>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit Review" OnClick="btnSubmit_Click" />
        <ajaxToolkit:RoundedCornersExtender ID="btnSubmit_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="btnSubmit">
        </ajaxToolkit:RoundedCornersExtender>
        <br />
        <br />
        <hr />
    </div>
    <asp:PlaceHolder ID="recentReviewsPlaceholder" runat="server">
        <h2 id="recent-reviews">Recent Reviews</h2>
    </asp:PlaceHolder>
    <ajaxToolkit:Accordion ID="eBookReviewsAccordion" runat="server" SelectedIndex="0" AutoSize="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="false">
        <HeaderTemplate>
            <hr />
            <h4><%# Eval("title") %>...</h4>
            Rating: <%# DeansWsccProject.App_Code.functions.getRating(Convert.ToString(Eval("rating"))) %> | Date: <%# Convert.ToString(Eval("reviewDate")).Remove(10, 9) %> | By <%# getReviewerLink(Convert.ToString(Eval("reviewer"))) %>
        </HeaderTemplate>
        <ContentTemplate>
            <%# Eval("review") %>
        </ContentTemplate>
    </ajaxToolkit:Accordion>

</asp:Content>
